import { ShopItemInfo } from "../../resource/info/ShopItemInfo";
import { ColorInfo } from "../../resource/info/ColorInfo";
import { BaseItem } from "../common/BaseItem";
import { NumInput } from "../common/NumInput";
import { GButton } from "../../../../com/mui/controls/GButton";
import { Language } from "../../../../extend/language/Language";
import { Alert } from "../../../../com/mui/controls/Alert";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { ObjCreate } from "../common/ObjCreate";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { ColorConfig } from "../../resource/ColorConfig";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ItemData } from "../../resource/info/ItemData";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { Cache } from "../../cache/Cache";
import { ClockManager } from "../../manager/ClockManager";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { SPlayerItem } from "../../../../Message/Public/SPlayerItem";
import { ItemsUtil } from "../shortcuts/item/ItemsUtil";
type int = number;
//class VipItemPanel
    
    export  class VipItemPanel /* flash.display.Sprite */
    {
        constructor(arg1: ShopItemInfo, arg2: int)
        {
            
            this.init(arg1, arg2);
            return;
        }

        /* internal  */init(arg1: ShopItemInfo, arg2: int): void
        {
            var shopItemInfo: ShopItemInfo;
            var index: int;
            var textFormatCenter: Object /* flash.text.TextFormat */;
            var tf: Object /* flash.text.TextField */;
            var colorInfo: ColorInfo;
            var propBg: Object /* flash.display.Bitmap */;
            var propItem: BaseItem;
            var bmpPrice: Object /* flash.display.Bitmap */;
            var numInput: NumInput;
            var btnBuyAndUse: GButton;
            var onBuyAndUse: Function;
            var onClose: Function;

            var loc1;
            colorInfo = null;
            numInput = null;
            onBuyAndUse = null;
            onClose = null;
            shopItemInfo = arg1;
            index = arg2;
            onBuyAndUse = (arg1: Object /* flash.events.MouseEvent */): void
            {
                var loc1=Language.getStringByParam(41285, numInput.currentNum.toString(), colorInfo.color, shopItemInfo.itemInfo.item.name, (numInput.currentNum * _price).toString());
                Alert.show(loc1, null, Alert.OK | Alert.CANCEL, null, onClose);
                return;
            }
            onClose = (arg1: int): void
            {
                if (arg1 == Alert.OK) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallBuyItemAndUse, {"shopItemInfo": shopItemInfo, "amount": numInput.currentNum}));
                    Dispatcher.addEventListener(EventName.ShopMallBuyItemSuccess, onBuySuccess);
                }
                return;
            }
            this.mouseEnabled = false;
            ObjCreate.createBg(0, 0, 128, 163, this);
            textFormatCenter = new GTextFormat(FontUtil.songtiName, 12, 11661311);
            textFormatCenter.align = flash.text.TextFormatAlign.CENTER;
            tf = ObjCreate.createTextField("", 32, 6, 65, 20, this, textFormatCenter);
            colorInfo = ColorConfig.instance.getItemColor(shopItemInfo.itemInfo.item.color);
            tf.htmlText = HTMLUtil.addColor(shopItemInfo.itemInfo.item.name, colorInfo.color);
            propBg = GlobalClass.getBitmap("PropBg");
            propBg.x = 30;
            propBg.y = 22;
            this.addChild(propBg);
            propItem = new BaseItem();
            propItem.isDragAble = false;
            propItem.label = "";
            propItem.move(35, 27);
            propItem.itemData = new ItemData(shopItemInfo.itemInfo.item.code);
            propItem.drawNow();
            propItem.amount = -1;
            propItem.setSize(60, 60);
            this.addChild(propItem);
            this.tfPrice = ObjCreate.createTextField("", 18, 92, 66, 20, this);
            this.updateByShopItem(shopItemInfo);
            bmpPrice = GlobalClass.getBitmap(GameDefConfig.instance.getEPrictUnitImg(shopItemInfo.unit));
            bmpPrice.x = 80;
            bmpPrice.y = 92;
            this.addChild(bmpPrice);
            numInput = new NumInput();
            numInput.x = 15;
            numInput.y = 110;
            numInput.maxNum = 99;
            numInput.currentNum = 1;
            this.addChild(numInput);
            if (index != 0) 
            {
                numInput.maxNum = 99;
                numInput.currentNum = 1;
            }
            else 
            {
                numInput.maxNum = 1;
            }
            btnBuyAndUse = ObjCreate.createGButton(Language.getString(41284), 24, 133, 80, 26, this, "ButtonLarge");
            btnBuyAndUse.addEventListener(flash.events.MouseEvent.CLICK, onBuyAndUse);
            return;
        }

        public updateByShopItem(arg1: ShopItemInfo): void
        {
            var loc4=null;
            var loc5=0;
            var loc7=0;
            var loc1=arg1.tshopSell.price;
            var loc2=arg1.tshopSell.offer;
            var loc3=arg1.tshopSell.activeOffer;
            var loc6=Cache.instance.shop.panicBuyDict;
            if (Cache.instance.shop.isShopMallDiscount && loc3 > 0) 
            {
                loc1 = loc3;
            }
            else if (loc2 > 0) 
            {
                loc1 = loc2;
            }
            if (ClockManager.instance.serverOpenDateNum <= 3) 
            {
                if ((loc4 = Cache.instance.shop.getPanicShopItem(arg1)) && loc6[loc4.itemCode]) 
                {
                    loc7 = loc6[loc4.itemCode];
                }
                if (loc4 && loc4.buyLimit - loc7 > 0) 
                {
                    loc1 = loc4.discount;
                }
            }
            this._price = loc1;
            this.tfPrice.htmlText = Language.getString(41283) + HTMLUtil.addColor(loc1.toString(), GlobalStyle.color6);
            return;
        }

        /* internal  */onBuySuccess(arg1: DataEvent): void
        {
            var loc1=arg1.data;
            var loc2=loc1["itemCode"];
            var loc3=loc1["amount"];
            var loc4;
            (loc4 = new SPlayerItem()).itemCode = loc2;
            var loc5=new ItemData(loc4);
            if (ItemsUtil.isVIPCard(loc5)) 
            {
                Dispatcher.removeEventListener(EventName.ShopMallBuyItemSuccess, this.onBuySuccess);
            }
            return;
        }

        /* internal */ /* var */tfPrice: Object /* flash.text.TextField */;

        /* internal */ /* var */_price: int;
    }
